package com.lyw.controller;

import com.lyw.mapper.EbProductMapper;
import com.lyw.model.EbNews;
import com.lyw.model.EbProduct;
import com.lyw.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/index")//迎宾的外号（工号）
public class IndexController {
    @Autowired
    private NewsService newService;

    @Autowired
    private EbProductMapper ebProductMapper;

    @RequestMapping("/index")//方法的外号
    //返回首页数据（model）和视图(jsp、html)方法
    public String index(Model model){
        //一、调用service获取数据
        //1.调用service层分页的新闻数据--新闻表
        List<EbNews> newes = newService.list(1, 7);
        //2.调用service层分页的商品数据--商品表
        //调用service层表示所有商品分类数据
        //二、将数据绑定到model
        //4、将数据绑定到model中 key-value
        model.addAttribute("newes",newes);
        List<EbProduct> ebProducts = ebProductMapper.selectByExample(null);
        model.addAttribute("goodsData",ebProducts);
        //三、返回视图
        return "index";
    }
}
